﻿using RN;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SendMail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string s = Request.QueryString["Type"];
            mailType.Value = s;
            int type;
            
            try
            {
                type = Convert.ToInt32(s);
            }
            catch (Exception)
            {
                type = 2;
            }

            if (Definitions.EMAIL_TYPE_RECEIVE == type)
            {
                MailClient mc = (MailClient)Session[Definitions.MAIL_CLIENT];
                //List<Message> list = mc.ListMessages();
                string from = Request.QueryString["From"];
                string subject = Request.QueryString["Subject"];
                Message m = mc.readMessage(from, subject);
                
                if (m != null)
                {
                    Subject.Value = m.Subject;
                    mailType.Value = type + "";
                    ToFrom.Value = m.From;
                    MailContent.Value = m.Messages;
                }
                btSend.Text = "Back to List";
            }
        }
    }

    protected void Send(object sender, EventArgs e)
    {
        Client cl = (Client)Session[Definitions.CURRENT_CLIENT];
             
        if (mailType.Value == "1")
        {
            MailClient mc = (MailClient) Session[Definitions.MAIL_CLIENT];
            mc.sendMessage(cl.username, ToFrom.Value, Subject.Value, MailContent.Value);
        }

        Response.Redirect("Index.aspx?user=" + cl.username);   
    }
}